var fs = require('fs-extra');
module.exports = {
    nowDate: function nowDate() {
        var now_date = new Date();
        var year = now_date.getFullYear();
        var month = now_date.getMonth() + 1 > 9 ? now_date.getMonth() + 1 : '0' + (now_date.getMonth() + 1);
        var data = now_date.getDate() >= 10 ? now_date.getDate() : '0' + now_date.getDate();
        var time = now_date.getHours() >= 10 ? now_date.getHours() : '0' + now_date.getHours();
        var minutes = now_date.getMinutes() >= 10 ? now_date.getMinutes() : '0' + now_date.getMinutes();
        var date = year + '-' + month + '-' + data + ' ' + time + ':' + minutes;
        return date;
    },
    delFiles: function delFils(images) {
        for (var i in images) {
            fs.remove(images[i], function (err) {
                if (err) {
                    console.log('err');
                }
            })
        }
    },
    setInfo: function setInfo(data) {
        var info = [];
        if (parseInt(data.number) > 1) {
            for (var i = 0; i < parseInt(data.number); i++) {
                info[i] = {
                    count: parseInt(data.count[i]),
                    size: data.size[i]
                }
            }
        } else {
            info[0] = {
                count: parseInt(data.count),
                size: data.size
            }
        }
        return info;
    },
    getImgPath: function getImgPath(val) {
        var imgsPath = [];
        var myRe = val.match(/<img.*?(?:>|\/>)/gi);
        var imgPath = /src=['"]?([^'"]*)['"]?/i;
        if (myRe != null) {
            myRe.forEach(function (item) {
                imgsPath.push(item.match(imgPath)[1]);
            });
        }
        return imgsPath;
    },
    getVideoPath: function getVidePath(val) {
        var videoPath = [];
        var myRe = val.match(/<video.*?(?:>)/gi);
        var regular = /src=['"]?([^'"]*)['"]?/i;
        if (myRe != null) {
            myRe.forEach(function (item) {
                videoPath.push(item.match(regular)[1]);
            });
        }
        return videoPath;
    }
};